package view;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;

public class Camera
{

    private Pixmap myPixmap;
    private Dimension myDisplaySize;
    private double myViewProportion;
    private Point myTopLeft;

    public Camera(Point topLeft, Dimension displaySize)
    {
        this(topLeft, displaySize, 1.0);
    }

    public Camera(Point topLeft, Dimension displaySize, double viewProportion)
    {
        myTopLeft = topLeft;
        myDisplaySize = displaySize;
        myViewProportion = viewProportion;
    }

    public void drawView(Graphics g)
    {

        myPixmap.drawFromCamera(g, myTopLeft, getViewSize(), myDisplaySize);
    }

    private Dimension getViewSize()
    {
        Dimension viewSize = new Dimension();
        viewSize.width = (int) (myDisplaySize.width * myViewProportion);
        viewSize.height = (int) (myDisplaySize.height * myViewProportion);
        return viewSize;
    }

    public void changeDisplaySize(Dimension newSize)
    {
        myDisplaySize = new Dimension(newSize);
    }

    public void zoom(double zoomFactor)
    {
        myViewProportion *= zoomFactor;
    }

    public void setPixmap(Pixmap pixmap)
    {
        myPixmap = pixmap;
    }

    public void move(int left, int up)
    {
        myTopLeft.x += left;
        myTopLeft.y += up;
    }

    public Rectangle getCurrentViewRectangle()
    {
        return new Rectangle(myTopLeft.x, myTopLeft.y, getViewSize().width,
                getViewSize().height);
    }
}
